package com.king.edu.domain;

import java.util.LinkedList;

/**
 * @ClassName: LimitedQueue
 * @Description: TODO
 * @Author: wangchangyong
 * @Date: 2020/6/10 16:05
 * @Version: 1.0.0
 **/
public class LimitedQueue<E> extends LinkedList<E> {

    private int limit;

    public LimitedQueue(int limit) {
        this.limit = limit;
    }

    @Override
    public boolean add(E o) {
        super.add(o);
        while (size() > limit) {
            super.remove();
        }
        return true;
    }


    public static void main(String[] args) {

        LimitedQueue<String> qu = new LimitedQueue<>(2);
        qu.add("1");
        qu.add("2");
        qu.add("3");

        System.out.println(qu);
    }
}
